﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CanvasEx;
using System.Windows.Media;

namespace Utility
{
    public class CustonCanvas : UserControl
    {
        private System.Windows.Forms.Integration.ElementHost elementHost1;
        private MyCanvas myCanvas;
        public CustonCanvas()
        {
            InitializeComponent();

            elementHost1.Width = this.Width;
            elementHost1.Height = this.Height;

            myCanvas =  new MyCanvas();            
            this.elementHost1.Child = myCanvas;
            myCanvas.Width = elementHost1.Width;
            myCanvas.Height = elementHost1.Height;

            System.Windows.Controls.TextBlock coordinate = new System.Windows.Controls.TextBlock();
            coordinate.Text = myCanvas.CoordinatePosition;
            coordinate.Margin = new System.Windows.Thickness(0,0,80,6);
            
        }

        public Painter CreatePainter(System.Drawing.Color color)
        {
            Painter p =  new Painter(myCanvas);            
            p.Color = Color.FromArgb(color.A, color.R, color.G, color.B);

            return p;
        }
              

        private void InitializeComponent()
        {
            this.elementHost1 = new System.Windows.Forms.Integration.ElementHost();
            this.SuspendLayout();
            // 
            // elementHost1
            // 
            this.elementHost1.Location = new System.Drawing.Point(0, 0);
            this.elementHost1.Name = "elementHost1";
            this.elementHost1.Size = new System.Drawing.Size(409, 332);
            this.elementHost1.TabIndex = 0;
            this.elementHost1.Text = "elementHost1";
            this.elementHost1.Child = null;
            // 
            // CustonCanvas
            // 
            this.Controls.Add(this.elementHost1);
            this.Name = "CustonCanvas";
            this.Size = new System.Drawing.Size(424, 347);
            this.SizeChanged += new System.EventHandler(this.CustonCanvas_SizeChanged);
            this.ResumeLayout(false);

        }

        private void CustonCanvas_SizeChanged(object sender, EventArgs e)
        {
            elementHost1.Width = this.Width;
            elementHost1.Height = this.Height;            
            
            myCanvas.Width = elementHost1.Width;
            myCanvas.Height = elementHost1.Height;
        }
    }
}
